package com.parkingwang.vehiclekeyboard.demo.keyboard

import android.content.Context
import android.support.v4.app.FragmentManager

/**
 * @author 黄浩杭 (huanghaohang@parkingwang.com)
 * @version 2.1
 * @since 1.13
 */
class VehicleKeyboardView {

    private var keyboardCallback: KeyboardCallback? = null
    private lateinit var manager: FragmentManager

    private var popupWindow: VehicleBottomDialog? = null

    fun onCreate(context: Context, manager: FragmentManager) {
        this.manager = manager
        initKeyboard(context)
    }

    private fun initKeyboard(context: Context) {
        popupWindow = VehicleBottomDialog()
    }

    fun setKeyboardCallback(keyboardCallback: KeyboardCallback) {
        this.keyboardCallback = keyboardCallback
        popupWindow?.setKeyboardCallback(keyboardCallback)
    }

    fun setHideOKKey(isHide: Boolean){
        popupWindow?.setHideOKKey(isHide)
    }

    fun update(plate: String) {
        popupWindow?.updateNumber(plate)
    }

    fun show() {
        popupWindow?.show(manager)
    }

    fun onDestroy() {
        if(popupWindow != null && popupWindow!!.isVisible) {
            popupWindow?.dismiss()
        }
    }
}
